<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理端登陆页</title>
    <link rel="stylesheet" type="text/css" href="./static/css/login.css">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
    <!-- <srcipt src="static/js/login.js"></srcipt> -->
</head>

<body>
    <section>
        <!-- 登录框 -->
        <div class="container">
            <div class="form" id="loginfor">
                <div>
                    <div class="inputBox">
                        <img src="./static/images/半身像.png" class="innerImg">
                        <div style="margin-left: 10px;"><input type="text" placeholder="账号" v-model="usersid"></div>
                    </div>
                    <div class="inputBox">
                        <!-- <img src="./static/images/锁住.png" class="innerImg"> -->
                        <img src="https://636c-cloud1-8g54d6xb74e96e7d-1311924947.tcb.qcloud.la/images/%E9%94%81%E4%BD%8F.png?sign=65c55b14e1501ce0cf4ce8fe645157eb&t=1661251428"
                            class="innerImg">
                        <div style="margin-left: 10px;"><input type="password" placeholder="密码" v-model="userspass">
                        </div>
                    </div>
                    <div class="forget">
                        <div style="border-left: 1px solid rgb(196,196,196);margin-right:5%"></div>
                        <a href="./passwordFind.html">
                            <div style="cursor: pointer;">找回密码</div>
                        </a>
                    </div>
                    <div style="width: 100%;display:flex;justify-content:center;margin-top: 6px;" @click="register()">
                        <div class="loginbottom">登录</div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- <srcipt src="static/js/login.js"></srcipt> -->
</body>

</html>
<script>
    var vm = new Vue({
        el: "#loginfor",
        data() {
            return {
                usersid: "",
                userspass: "",
            }
        },
        methods: {
            register() {
                console.log(this.usersid, this.userspass)
                console.log("1.1")
                var a=this.usersid;
                var b=this.userspass;
                /////////////////////////////////////////////////
                //初始化
                let first = function (callback) {
                    var c1 = new cloud.Cloud({
                        //必填，表示是未登录模式
                        identityless: true,
                        //资源方 AppID
                        resourceAppid: 'wx96f760966921f98a',
                        //资源方环境 ID
                        resourceEnv: 'cloud1-8g54d6xb74e96e7d',
                    })
                    c1.init()
                    //回调
                    callback(c1)
                };
                //完成初始化后再回调，即可访问云数据库
                let callback = function (c1) {
                    // 你要访问的各种操作写在这个callback函数里
                    const db = c1.database();
                    db.collection('Users').where({realName:a}).get({
                        success: res => {
                            console.log(res.data[0]._openid);
                            console.log("成功回调小程序");
                            if(res.data[0].webPassword==b)
                            {
                                //登录暂未清楚传递到哪里
                                // alert("密码正确！但登录功能未完善，敬请期待")
                                location.href='./index.html'
                            }
                            else{
                                alert("密码错误！")
                            }
                            
                        },
                        fail: res => {
                            console.log(res);
                            console.log(3);
                        }
                    })

                };
                first(callback);


                ////////////////////////////////

            }
        }
    })

</script>